package com.tikeyc.loveshare.activity.tab;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import com.tikeyc.loveshare.R;
import com.tikeyc.loveshare.adapter.home.THomeAdapter;

import org.xutils.common.util.DensityUtil;

/**
 * Created by public1 on 2017/4/24.
 */

public class THomeFragment extends Fragment {

    private LinearLayout mView;

    private GridView home_fragment_gridView;
    private LinearLayout home_fragment_listheadView;
    private ListView home_fragment_listView;
    private THomeAdapter.GridViewAdapter gridAdapter;
    private THomeAdapter.ListViewAdapter listAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {


        mView = (LinearLayout) inflater.inflate(R.layout.home_fragment,container,false);

        initView();

        return mView;
    }

    private void initView() {
        home_fragment_listheadView = (LinearLayout) View.inflate(getContext(),R.layout.home_fragment_listheadview,null);
        home_fragment_gridView = (GridView) home_fragment_listheadView.findViewById(R.id.home_fragment_gridView);
        home_fragment_gridView.setNumColumns(3);
        home_fragment_gridView.setColumnWidth(DensityUtil.getScreenWidth()/3);
        home_fragment_gridView.setVerticalSpacing(20);
        gridAdapter = new THomeAdapter.GridViewAdapter(getContext());
        home_fragment_gridView.setAdapter(gridAdapter);
        home_fragment_gridView.setOnItemClickListener(gridItemClickListener);
        //
        home_fragment_listView = (ListView) mView.findViewById(R.id.home_fragment_listView);
        home_fragment_listView.addHeaderView(home_fragment_listheadView);
        listAdapter = new THomeAdapter.ListViewAdapter(getContext());
        home_fragment_listView.setAdapter(listAdapter);
        home_fragment_listView.setOnItemClickListener(listItemClickListener);
    }


    private AdapterView.OnItemClickListener gridItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        }
    };


    private AdapterView.OnItemClickListener listItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        }
    };

}
